#include "PauseLayer.h"
using namespace CocosDenshion;

PauseLayer::PauseLayer(void)
{
}


PauseLayer::~PauseLayer(void)
{
}


bool PauseLayer::init()
{
	bool bInit = false;
	do 
	{
		CC_BREAK_IF(!BasicLayer::init());
		setTouchEnabled(true);


		setupViews ();

		bInit = true;
	} while (0);

	return bInit;

}

void PauseLayer::setupViews()
{
	CCSprite* pSprite = CCSprite::create("pauseBack.png");
	pSprite->setPosition(ccp(getLayerSize().width/2,getLayerSize().height/2));
	this->addChild(pSprite);
	
	CCSprite* pPlayNormal = CCSprite::create("Play_normal.png");
	CCSprite* pPlayPressed = CCSprite::create("Play_pressed.png");
	CCMenuItemSprite* pMenuPlayItem = CCMenuItemSprite::create(pPlayNormal,pPlayPressed,this,menu_selector(PauseLayer::callback_Play));
	CCMenu* PlayMenu = CCMenu::create(pMenuPlayItem,NULL);
	
	CCSize msize = getLayerSize();
	PlayMenu->setPosition(ccp(msize.width/2,msize.height/2));
	this->addChild(PlayMenu);

}

void PauseLayer::callback_Play(CCObject* obj)
{
	if (      (CCUserDefault::sharedUserDefault()->getBoolForKey("MUSIC_PLAY",true) == true)  ) 
	{
		SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
	}

	CCDirector::sharedDirector()->resume();

	this->removeFromParent();

}

bool PauseLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	return true;
}

void PauseLayer::registerWithTouchDispatcher()
{
	CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-1,true);
}